package com.von.nhcf.service.impl;

import com.von.nhcf.entity.po.MemberPO;
import com.von.nhcf.entity.po.MemberPOExample;
import com.von.nhcf.mapper.MemberPOMapper;
import com.von.nhcf.service.MysqlMemberService;
import com.von.nhcf.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class MysqlMemberServiceImpl implements MysqlMemberService {
    @Autowired
    MemberPOMapper memberPOMapper;


    @Override
    public MemberPO getMemberPOByUsername (@RequestParam("loginacct")String username) {
        MemberPOExample example = new MemberPOExample();

        MemberPOExample.Criteria criteria = example.createCriteria();

        criteria.andLoginacctEqualTo(username);

        List<MemberPO> memberPOList = memberPOMapper.selectByExample(example);

        return memberPOList.get(0);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class, readOnly = false)
    @Override
    public void saveMemberPO(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }
}
